﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for categoryDAL
/// </summary>
public class CategoryDAL
{
    DataAccess db = new DataAccess();

	public CategoryDAL()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public DataTable GetAllCategory()
    {
        SqlParameter[] pmtList = new SqlParameter[1];
        pmtList[0]=db.AddParameter("category_id", DBNull.Value, SqlDbType.Int);

        return db.executeSelect("Select_Category", pmtList);
    }
    public DataTable getCategoryByID(int category_id){
        SqlParameter[] pmtList = new SqlParameter[1];
        pmtList[0] = db.AddParameter("category_id",category_id, SqlDbType.Int);
        return db.executeSelect("Select_Category", pmtList);

    }
    public DataTable getCategoryByParent_id(int parent_id)
    {
        SqlParameter[] pmtList = new SqlParameter[3];
        pmtList[0] = db.AddParameter("category_id", DBNull.Value, SqlDbType.Int);
        pmtList[1] = db.AddParameter("category_id", DBNull.Value, SqlDbType.Int);
        pmtList[2] = db.AddParameter("category_id", parent_id, SqlDbType.Int);
        return db.executeSelect("Select_Category", pmtList);
    }
    public int InsertCategory(category Category)
    {
        SqlParameter[] pmtList = new SqlParameter[5];
        pmtList[0] = db.AddParameter("category_id", DBNull.Value, SqlDbType.Int);
        pmtList[1] = db.AddParameter("category_name", Category.CategoryName, SqlDbType.NVarChar);
        pmtList[2] = db.AddParameter("category_des", Category.CategoryDes, SqlDbType.NVarChar);
        pmtList[3] = db.AddParameter("image", Category.CategoryImage, SqlDbType.NVarChar);
        pmtList[4] = db.AddParameter("parent_id", Category.ParentID, SqlDbType.Int);

        return db.executeUpdate("IS_Category", pmtList);
    }
    public int UpdateCategory(category Category)
    {
        SqlParameter[] pmtList = new SqlParameter[5];
        pmtList[0] = db.AddParameter("category_id", Category.CategoryID, SqlDbType.Int);
        pmtList[1] = db.AddParameter("category_name", Category.CategoryName, SqlDbType.NVarChar);
        pmtList[2] = db.AddParameter("category_des", Category.CategoryDes, SqlDbType.NVarChar);
        pmtList[3] = db.AddParameter("image", Category.CategoryImage, SqlDbType.NVarChar);
        pmtList[4] = db.AddParameter("parent_id", Category.ParentID, SqlDbType.Int);

        return db.executeUpdate("IS_Category", pmtList);
    }
    public int DeleteCategory(int category_id)
    {
        SqlParameter[] pmtList = new SqlParameter[1];
        pmtList[0] = db.AddParameter("category_id", category_id, SqlDbType.Int);

        return db.executeUpdate("DE_Category", pmtList);
    }
}